package com.xiaoma.tpo.dao;


import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.dto.FrcastQuestionInfoDto;
import com.xiaoma.verbal.domain.ForcastQuestionInfo;
import com.xiaoma.verbal.domain.QuQuestion;

@Repository
public class ForcastQuestionInfoDao extends BaseDaoImpl<ForcastQuestionInfo>{

	private static final Logger LOG = LoggerFactory.getLogger(ForcastQuestionInfo.class);
	//旧
	@SuppressWarnings("unchecked")
	public List<FrcastQuestionInfoDto> findByQuestionId(Integer questionId) {
		
		String sql = "select info.id, q.id as question_id, info.audio_seq_num, info.audio_code, info.audio_content,info.code from forcast_question_info info, qu_question q" +
				" where info.question_num = q.question_num" +
				" and q.id = ?";
		LOG.info("SQL:{} PARAMS:{}", sql);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(FrcastQuestionInfoDto.class, getNameHandler()), questionId);
        return (List<FrcastQuestionInfoDto>)result;
	}
	//新
	@SuppressWarnings("unchecked")
	public List<Object> findByQuestionIdNew(Integer questionId) {
		List<Object> allList = new ArrayList<Object>();
		String sqlQ = "select * from qu_question "
				+ " where id = ?";
		List<?> qResult = jdbcTemplate.query(sqlQ, new DefaultRowMapper(QuQuestion.class, getNameHandler()), questionId);
		String sql = "select info.id, q.id as question_id, info.audio_seq_num, info.audio_code, info.audio_content,info.code from forcast_question_info info, qu_question q" +
				" where info.question_num = q.question_num" +
				" and q.id = ?";
		LOG.info("SQL:{} PARAMS:{}", sql);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(FrcastQuestionInfoDto.class, getNameHandler()), questionId);
        allList.add(qResult);
        allList.add(result);
        return allList;
	}
}
